#include "myaction.h"
#include <QSplitter>
#include <QLabel>
#include <QLineEdit>
#include <QDebug>
MyAction::MyAction(QObject *parent): QWidgetAction(parent),lineEdit(new QLineEdit){

}

MyAction::~MyAction()
{
    //导致二次析构了,证明会自动回收
    // if(lineEdit!=nullptr)
    // {
    //     qDebug() << "lineEdit还没销毁呢" << Qt::endl;
    //     delete lineEdit;
    // }
}

QSplitter *MyAction::createWidget(QWidget *parent)//返回QSplitter这个类型不行吗？可以
{
    if(!parent->inherits("QMenu") && !parent->inherits("QToolBar")) return 0;

    auto splitter = new QSplitter(parent);
    auto label = new QLabel;
    label->setText(tr("请输入文字"));

    connect(lineEdit,&QLineEdit::returnPressed,this,&MyAction::sentText);

    splitter->addWidget(label);
    splitter->addWidget(lineEdit);

    return splitter;
}

void MyAction::sentText()
{
    emit getText(lineEdit->text());
    lineEdit->clear();
}




